<?php

namespace App\V3\V3_1\Controllers;

use Illuminate\Http\Request;
use App\V3\V3_1\Models\MaterielsTypeModel;
use App\V3\V3_1\Models\HcMaterielTypeModel;
use Illuminate\Support\Facades\DB;
use App\V3\V3_1\Services\HcMaterielTypeService;
use App\V3\V3_1\Models\AdminModel;
use App\V3\V3_1\Models\MaterielClassModel;
use App\V3\V3_1\Models\GoodsAlbumModel;
use Illuminate\Support\Facades\Validator;
use App\V3\V3_1\Models\HcMaterielClassModel;
use Illuminate\Support\Facades\Log;
use App\V3\V3_1\Models\AdminAddendumModel;
use OSS\OssClient;

class HcMaterielTypeController extends BaseController
{
    protected $ossClient;
    public function __construct(Request $request){
        parent::__construct($request);
        $this->ossClient=new OssClient(
            config('app.aliyun_oss_key'),
            config('app.aliyun_oss_secret'),
            config('app.aliyun_oss_endpoint')
            );
    }
    /**
     * 一键生成商品画册
     */
    public function addHcMaterielType(Request $request){
        //参数验证
        $validator = Validator::make($data = $request->all(), [
            'select_goods_ids' => 'required',//页面大小
        ],[
            'select_goods_ids.required' => '参数`选中的商品主键`缺失'
        ]);
        //参数错误响应
        if ($info = $validator->errors()->first()) {
            return $this->fail('',$info);
        }
     /*    $query = GoodsAlbumModel::where(['main_id'=>$this->getMainUserId()]);
        $total_num = $query->sum('number');//生成数
        $count = $query->count();//商品画册条数 */
        $userInfo = GoodsAlbumModel::select('number')->where(['main_id'=>$this->getMainUserId(),'user_id'=>$this->getUserId()])->first();
        if(empty($userInfo['number'])) $userInfo['number'] = 0;

       $adminInfo   = AdminAddendumModel::select('is_vip','album_amount','one_key_album_times')->where(['main_id'=>$this->getMainUserId()])->first()->toArray();

        if(!empty($adminInfo) && in_array($adminInfo['is_vip'],[1,2])){
/*
            if($adminInfo['one_key_album_times'] != -1 && $total_num >= $adminInfo['one_key_album_times']){

                return $this->fail('','您一键生成商品画册次数，已达到设置数量！');
            }

           if($adminInfo['album_amount'] != -1 && $total_num >= $adminInfo['album_amount']){

                return $this->fail('','您生成商品画册彩页，已达到设置数量！');
            } */

        }else{

            return $this->fail('','您还不是VIP会员，还不能一键生成商品画册！');
        }

        $condition['main_id']  = $this->getMainUserId();

        $class_list = MaterielClassModel::select('id','class_name','full_class_no','parent_id','main_id','is_active','delete_flag')
                    ->where(['main_id'=> $this->getMainUserId()])->where('delete_flag',0)->get()->toArray();

        if(empty($class_list)){

            return $this->fail('','您还没有添加物料商品分类，请添加重试！');
        }

        $list = MaterielsTypeModel::select('*')->where($condition)->where('delete_flag',0)->get()->toArray();

        if(empty($list)) return $this->fail('','您还没有添加物料商品，请添加重试！');


        DB::beginTransaction();
        try {
            if(!empty($list)){

                $info = AdminModel::select('company_name')->where('id', $this->getMainUserId())->first();

                $gData['create_time'] = time();
                $gData['number']      = $userInfo['number']+1;
                $gData['main_id']     = $this->getMainUserId();
                $gData['user_id']     = $this->getUserId();
                $gData['p_a_name']  = !empty($info['company_name'])?$info['company_name']:'';

                $gInfo = GoodsAlbumModel::select('id')->where(['main_id'=>$this->getMainUserId()])->first();

                if(!empty($gInfo)){

                    $album_id = $gInfo['id'];
                    GoodsAlbumModel::where(['main_id'=>$this->getMainUserId(),'id'=>$album_id])->update($gData);
                }else{

                    $album_id = GoodsAlbumModel::insertGetId($gData);
                }

                $selgoodsArr = explode(',', $data['select_goods_ids']);

                $albumArr = [];

                foreach ($list as $mk=>$mv){

                    $condition['id'] = $mv['id'];
                    $condition['album_id'] = $album_id;
                    $info = HcMaterielTypeModel::where($condition)->first();

                    if(in_array($mv['id'], $selgoodsArr)){

                        if($mv['is_album'] != 1){
                            MaterielsTypeModel::where('id',$mv['id'])->update(['is_album'=>1]);
                        }
                        $albumArr['id']                     = $mv['id'];
                        $albumArr['materiel_name']          = $mv['materiel_name'];
                        $albumArr['type_name']              = $mv['type_name'];
                        $albumArr['materiel_img']           = $mv['materiel_img'];
                        $albumArr['materiel_thumbnail_img'] = $mv['materiel_thumbnail_img'];
                        $albumArr['materiel_no']            = $mv['materiel_no'];
                        $albumArr['materiel_class_id']      = $mv['materiel_class_id'];
                        $albumArr['materiel_unit']          = $mv['materiel_unit'];
                        $albumArr['length']                 = $mv['length'];
                        $albumArr['width']                  = $mv['width'];
                        $albumArr['height']                 = $mv['height'];
                        $albumArr['attribute']              = $mv['attribute'];
                        $albumArr['cost']                   = $mv['cost'];
                        $albumArr['last_cost']              = $mv['last_cost'];
                        $albumArr['selling_price']          = $mv['selling_price'];
                        $albumArr['lower_selling_price']    = $mv['lower_selling_price'];
                        $albumArr['main_id']                = $mv['main_id'];
                        $albumArr['remark']                 = $mv['remark'];

                        if(empty($info)){

                            $albumArr['created_at'] = time();
                            $albumArr['album_id']   = $album_id;
                            HcMaterielTypeModel::add($albumArr);

                        }else{

                            $albumArr['updated_at']  = time();
                            HcMaterielTypeModel::where($condition)->update($albumArr);
                        }
                    }else{
                        
                        if($mv['is_album'] == 1){
                            MaterielsTypeModel::where('id',$mv['id'])->update(['is_album'=>0]);
                        }

                        if(!empty($info)){
                           
                            HcMaterielTypeModel::where($condition)->delete();
                        }
                    }
                }

                foreach ($class_list as $cv){

                    $cCondition['id'] = $cv['id'];
                    $cInfo = HcMaterielClassModel::where($cCondition)->first();

                    if(empty($cInfo)){
                        $cv['created_at'] = time();
                         HcMaterielClassModel::insert($cv);

                    }else{
                        $cv['updated_at']  = time();
                        HcMaterielClassModel::where($cCondition)->update($cv);
                    }
                }

                DB::commit();
                $this->log('一键生成商品画册', $data);
                return $this->success(['album_id'=>$album_id]);
            }
        } catch (\Exception $e) {
            DB::rollBack();//事务回滚
            //异常响应
            return $this->fail($e->getMessage(),'商品画册，生成失败！');
        }

    }

    /**
     * 物料商品列表
     */
    public function selectGoods(Request $request)
    {
        $keyword = empty($request->keyword)?'':$request->keyword;
        $condition = [];

        if(!empty($request->materiel_class_id)) {
            $condition['a.materiel_class_id'] = ['EQ' => $request->materiel_class_id];
        }
       $list = HcMaterielTypeService::SelectMaterielType(
                $this->getMainUserId(),
                $keyword,
                $condition,
                $request->pageSize,
                $request->currentPage
                );

       if(!empty($list['data'])){

           foreach ($list['data'] as $k=>$v){
               $info = HcMaterielTypeModel::where('id',$v['id'])->first();

               if(!empty($info)){
                   $list['data'][$k]['is_exist']=1;
               }else{
                   $list['data'][$k]['is_exist']=0;
                   }
           }
       }
       $this->log('商品画册，物料商品列表', $list);
        return $this->success($list);
    }
    /**
     * 商品画册列表
     * @param Request $request
     */
    public function productPicAlbumList(Request $request){

        $adminInfo   = AdminAddendumModel::select('is_vip','album_page_amount')->where(['main_id'=>$this->getMainUserId()])->first()->toArray();

        if(!empty($adminInfo) && in_array($adminInfo['is_vip'],[1,2])){

            if($adminInfo['album_page_amount'] >0 && $request->current_page >= $adminInfo['album_page_amount']){

                return $this->fail('','您当前彩页超出限制'.$adminInfo['album_page_amount'].'页，超出部分未生成彩页');
            }

        }else{
                return $this->fail('','您还不是VIP会员，不能展示彩页！');
        }

        $validator = Validator::make($data = $request->all(), [
            'album_id' => 'required|integer'//商品画册id
        ],
            [
                'album_id.required' => '商品画册id,必要参数',
                'album_id.integer'  => '商品画册id,类型为正整数',
            ]
            );

        if ($info = $validator->errors()->first()) {
            return response()->json([
                'code' => 1,
                'msg' => $info,
                'data' => '',
            ]);
        }

        $keyword = empty($request->keyword)?'':$request->keyword;
        $condition = [];
        $nextClassIdArr = [];
        $condition1=[];
        $aInfo = GoodsAlbumModel::select('id','p_a_name','main_id','album_cover_img','mobile','background_music','flag','album_logo')
        ->where(['id' => $request->album_id])->where(['is_del'=>0])->first();
        if(!empty($request->materiel_class_id)) {
            $nextClassIdArr[] = $request->materiel_class_id;
        }
        if(!empty($request->parent_class_id)){

            $next_class_list = HcMaterielTypeService::nextClass($aInfo['main_id'],$request->parent_class_id);

            if(!empty($next_class_list)){

                foreach ($next_class_list as $k=>$v){

                    $nextClassIdArr[$k] = $v['id'];
                }
            }
        }
         $condition['is_album'] = 1;
         if(!empty($aInfo)){
             if(!empty($aInfo['album_cover_img'])){

                 $aInfo['album_cover_img'] = self::addWatermark($this->ossClient, $aInfo['album_cover_img'], $this->getMainUserId());
             }
             if(!empty($aInfo['album_logo'])){

                 $aInfo['album_logo'] = self::addWatermark($this->ossClient, $aInfo['album_logo'], $this->getMainUserId());
             }
         }else{
            return response()->json(['code' => 1,'msg'  => '此商品画册，没有找到！','data' =>""]);
         };
         $condition['album_id'] = $request->album_id;

         $list = HcMaterielTypeService::HcmaterielTypeSelect(
            $this->getMainUserId(),
            $keyword,
            $condition,
            $nextClassIdArr,
            $request->page_size,
            $request->current_page
            );
         $data = [];
         $data['pageSize']=$request->page_size;
         $data['currentPage']=$request->current_page;
        $list = HcMaterielTypeService::withSearch($list['data'], $aInfo['main_id'], $data, $condition, $condition1, $keyword);

        if(!empty($list['data'])){
            foreach ($list['data'] as $k01=>$v01){
                if (!empty($v01['next_class'])){
                  foreach ($v01['next_class'] as $k02=>$v02){
                      if(!empty($v02['next_hc_type'])){
                          foreach ($v02['next_hc_type'] as $k03=>$v03){
                              $list['data'][$k01]['next_class'][$k02]['next_hc_type'][$k03]['materiel_img'] = self::addWatermark($this->ossClient, $v03['materiel_img'], $this->getMainUserId());
                          }
                      }
                  }
                }
            }
        }
        return $this->success(['album_data'=>$aInfo,'list'=>$list]);
    }

    /**
     * 商品画册信息
     * @param Request $request
     */
    public function productPicAlbumInfo(Request $request)
    {
        if(empty($request->id)) {
            return $this->fail('', '参数`商品画册id`缺失');
        }

        return $this->success(HcMaterielTypeService::info($request->id));
    }


    public function delPicAlbum(Request $request){

        if(empty($request->album_ids)) {
            return $this->fail('', '参数`画册id`缺失');
        }
        $album_ids_arr = explode(',',$request->album_ids);
        DB::beginTransaction();
        try {
            $condition['main_id'] = $this->getMainUserId();
            $gList = GoodsAlbumModel::select('id','album_cover_img','background_music')->where($condition)->whereIn('id',$album_ids_arr)->get();
            if(!empty($gList)){
                $gaList = HcMaterielTypeModel::where($condition)->whereIn('album_id',$album_ids_arr)->get();
                GoodsAlbumModel::where($condition)->whereIn('id',$album_ids_arr)->delete();
                HcMaterielTypeModel::where($condition)->whereIn('album_id',$album_ids_arr)->delete();
               foreach ($gList as $gv){
                   if(!empty($gv['album_cover_img'])){
                       //删除OSS里的文件
                       self::delOssFilePath($gv['album_cover_img'], $this->ossClient, $this->getMainUserId());
                   }

                   if(!empty($gv['background_music'])){
                       //删除OSS里的文件
                       self::delOssFilePath($gv['background_music'], $this->ossClient, $this->getMainUserId());
                   }
                   if(!empty($gv['album_logo'])){
                       //删除OSS里的文件
                       self::delOssFilePath($gv['album_logo'], $this->ossClient, $this->getMainUserId());
                   }
               }
               if(!empty($gaList)){
                   foreach ($gaList as $gav){
                       //删除OSS里的文件
                       self::delOssFilePath($gv['materiel_img'], $this->ossClient, $this->getMainUserId());
                   }
               }
                $this->log('删除画册商品', $request->id);
                DB::commit();
                return $this->success();
             }
        } catch (\Exception $e) {
            DB::rollBack();
            Log::debug('删除商品信息异常'.var_export($request->all(), true));
            return $this->fail('', $e->getMessage());
        }
    }

    public function editPicAlbum(Request $request){

        $data = $request->all();
        if(!empty($album_img_files = $request->file('album_cover_img'))){

            $res = self::handlePicFormat($album_img_files,'p','图片格式,不正确！');//判断文件格式

            if(!empty($res)) return $res;

            if($album_img_files->isValid()){
                $path = $album_img_files->store('huace/goods/img/'.date('Y').'-'.date('m').'-'.date('d'));

                $imgRes = self::addOssUploadImg($this->ossClient,$this->getMainUserId(),$album_img_files, $path);

                if($imgRes['code'] ==1) return response()->json($imgRes);

                $data['album_cover_img'] = $imgRes['data'];

            }else{
             return  $this->fail('','图片上传失败！');

            }
        }
        if(!empty($music_files = $request->file('background_music'))){

            $res = self::handlePicFormat($music_files,'m','音乐格式,不正确！');//判断文件格式

            if(!empty($res)) return $res;

            if($music_files->isValid()){
                $path = $music_files->store('huace/goods/music/'.date('Y').'-'.date('m').'-'.date('d'));

                $imgRes = self::addOssUploadImg($this->ossClient,$this->getMainUserId(),$music_files, $path);

                if($imgRes['code'] ==1) return response()->json($imgRes);

                $data['background_music'] = $imgRes['data'];

            }else{
                return  $this->fail('','上传失败！');
            }
        }


        if(!empty($music_files = $request->file('album_logo'))){

            $res = self::handlePicFormat($music_files,'p','画册logo格式,不正确！');//判断文件格式

            if(!empty($res)) return $res;

            if($music_files->isValid()){
                $path = $music_files->store('huace/goods/img/'.date('Y').'-'.date('m').'-'.date('d'));

                $imgRes = self::addOssUploadImg($this->ossClient,$this->getMainUserId(),$music_files, $path);

                if($imgRes['code'] ==1) return response()->json($imgRes);

                $data['album_logo'] = $imgRes['data'];

            }else{
                return  $this->fail('','上传失败！');
            }
        }

        if(isset($data['pa_id'])){

            $data['id'] = $data['pa_id'];
            unset($data['pa_id']);
        }
        $info = GoodsAlbumModel::select('id','album_cover_img','background_music')->where(['id'=>$data['id']])->first();
        DB::beginTransaction();
        try {
            if(!empty($info)){
                $bool = GoodsAlbumModel::where(['id'=>$data['id']])->update($data);
                if($bool){
                    if(!empty($request->file('album_cover_img'))){
                        //删除OSS里的文件
                        self::delOssFilePath($info['album_cover_img'], $this->ossClient, $this->getMainUserId());
                    }

                    if(!empty($request->file('background_music'))){
                        //删除OSS里的文件
                        self::delOssFilePath($info['background_music'], $this->ossClient, $this->getMainUserId());
                    }

                    if(!empty($request->file('album_logo'))){
                        //删除OSS里的文件
                        self::delOssFilePath($info['album_logo'], $this->ossClient, $this->getMainUserId());
                    }
                    DB::commit();
                    $this->log('商品画册，物料商品列表', $data);
                   return $this->success();
                }
                  return  $this->fail('','修改失败');
            }else{
                return  $this->fail('','要修改的画册，没有找到！');
            }
        } catch (\Exception $e) {
            DB::rollBack();
            return $this->fail('',$e->getMessage());
        }
    }
    /**
     * 删除画册商品（多个用逗号分隔）
     * @param Request $request
     */
    public function delGoods(Request $request){

        if(empty($request->album_id)) {
            return $this->fail('', '参数`画册id`缺失');
        }

            if(empty($request->ids)) {
                return $this->fail('', '参数`画册商品id`缺失');
            }

            $pa_id_arr   = explode(',', $request->ids);

            $checkMateriel = HcMaterielTypeService::checkMateriel(
                $this->getMainUserId(),
                $pa_id_arr
                );

            if(!$checkMateriel) {
                return $this->fail('', '画册商品不存在，请重试');
            }
            $list = HcMaterielTypeModel::select('materiel_img')->where(['main_id'=>$this->getMainUserId(),'album_id'=>$request->album_id])
            ->whereIn('id', $pa_id_arr)->get();
            $bool=HcMaterielTypeModel::where(['main_id'=>$this->getMainUserId(),'album_id'=>$request->album_id])
            ->whereIn('id', $pa_id_arr)->delete();
            if($bool){
                if(is_array($list)){
                    foreach ($list as $v){
                        //删除OSS里的文件
                        self::delOssFilePath($v['materiel_img'], $this->ossClient, $this->getMainUserId());
                    }
                }
            }
            $this->log('删除画册商品', $request->id);
            return $this->success();
    }

    public function updGoods(Request $request){

        $validator = Validator::make($data = $request->all(), [
            'id'       => 'required',//商品id
            'album_id' => 'required',//画册id

        ],[
            'album_id.required' => '参数`画册id`缺失',
            'id.required'       => '参数`画册商品id`缺失'

        ]);

        if ($info = $validator->errors()->first()) {
            return response()->json([
                'code' => 1,
                'msg' => $info,
                'data' => '',
            ]);
        }

        if(!empty($materiel_img_files = $request->file('materiel_img'))){

            $res = self::handlePicFormat($materiel_img_files,'p','商品图片格式,不正确！');//判断文件格式

            if(!empty($res)) return $res;

            if($materiel_img_files->isValid()){

                $path = $materiel_img_files->store('huace/goods/img/'.date('Y').'-'.date('m').'-'.date('d'));

                $imgRes = self::addOssUploadImg($this->ossClient,$this->getMainUserId(),$materiel_img_files, $path);

                if($imgRes['code'] ==1) return response()->json($imgRes);

                $data['materiel_img'] = $imgRes['data'];

            }else{
                return  $this->fail('','商品图片上传失败！');
            }
        }
        $data['length'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;
        $data['width'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;
        $data['height'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;
        $data['weight'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;
        $data['cost'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;
        $data['selling_price'] = isset($data['length'])?($data['length'] < 0)?0:$data['length']:0;

        $data['main_id'] = $this->getMainUserId();
        $data['remark'] = empty($data['remark'])?'':$data['remark'];
        $data['materiel_img'] = empty($data['materiel_img'])?'':$data['materiel_img'];
        $data['attribute'] = empty($data['attribute'])?'':$data['attribute'];
        $data['type_name'] = empty($data['type_name'])?$data['materiel_name']:$data['type_name'];

        DB::beginTransaction();
        try {
            $gCondition['id'] = $data['id'];
            $gCondition['album_id']= $data['album_id'];
            $gCondition['main_id'] = $this->getMainUserId();
            $info = HcMaterielTypeModel::select('materiel_img')->where($gCondition)->first();

            if(empty($info)) return $this->fail('','没有找到要修改的画册商品');

            $bool = HcMaterielTypeModel::where($gCondition)->update($data);

            if($bool){
                if(!empty($request->file('materiel_img'))){
                    //删除OSS里的文件
                    self::delOssFilePath($info['materiel_img'], $this->ossClient, $this->getMainUserId());
                }
            }
            DB::commit();
            return $this->success();
        }
        catch(\Exception $e) {
            DB::rollBack();
            Log::debug('编辑商品信息异常'.var_export($data, true));
            return $this->fail('', $e->getMessage());
        }
    }

    /**
     * 图片上传到oss系统
     * @param unknown $client
     * @param unknown $file
     */
    static public function addOssUploadImg($client,$mainId,$file,$path){

        $res = handleUploadFileType($file);

       if(!empty($res)) return $res;

         $size = $file -> getSize();

         $result = saveFileSize(['main_id'=>$mainId], $size,$path);

         if($result['code'] == 1) return $result;

        try {

            $fullPath = '/uploads/'.$path;
            $ossPath  = ltrim($fullPath,'./');
            $path     = public_path().$fullPath;
            $client -> uploadFile(config('app.aliyun_oss_bucket'), $ossPath, $path);
            @unlink($path);
            $url = config('app.aliyun_oss_bucket_url').$fullPath;
            return ["code"=>0,"msg"=>"success","data"=>$url];

        } catch (\Exception $e) {

            return ["code"=>1,"msg"=>"OSS系统，上传图片失败！","data"=>""];
        }
    }
    /**
     * 添加水印
     * @param unknown $file
     */
    static public function addWatermark($client,$file,$mainId){

        if(empty($file)) return $file;

        $adminInfo = AdminAddendumModel::select('clear_watermark_or_not')->where(['main_id'=>$mainId])->first();

        if($adminInfo['clear_watermark_or_not']==1){

            return $file;
        }else{

                try {
                $delPath = strstr($file, 'uploads/');

                $imgInfo = $client->getObjectMeta(config('app.aliyun_oss_bucket'), $delPath);

                if(strpos($imgInfo['content-type'],'image/') !== false){

                    return $file = $file.config('app.aliyun_oss_img_watermark');
                }

            return $file;
            } catch (\Exception $e) {

            }
        }
    }

    /**
     * 删除oss里的文件
     * @param unknown $file
     * @param unknown $mainId
     */
    static public function delOssFilePath($file,$client,$mainId){
        if(empty($file)) return $file;
        if(strpos($file,'/uploads/huace/') !== false){
           DB::beginTransaction();
           try {
            $delPath = strstr($file, 'uploads/');
            $imgInfo=$client->getObjectMeta(config('app.aliyun_oss_bucket'), $delPath);
            AdminAddendumModel::where(['main_id'=>$mainId])
            ->decrement('file_total_size', $imgInfo['content-length']);
            $client -> deleteObject(config('app.aliyun_oss_bucket'), $delPath);
            DB::commit();
            } catch (\Exception $e) {
                DB::rollBack();
                return "";
            }
        }
    }

    /**
     * 处理图片和视频格式
     */
    static public function handlePicFormat($files,$flag,$msg){

        $pic_video_format = 'mp3,aac,wav,wma,cda,flac,m4a,mid,mka,mp2,mpa,mpc,ape,ofr,ogg,ra,wv,ac3,dts,
                            flash,mpeg,mpeg-2,mpeg-4,midi,wmv,asf,asx,rm,rmvb,mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,
                            bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,
                            ufo,eps,ai,raw,wmf,webp,avif,apng';

        $pic_format       = 'bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,wmf,webp,avif,apng';

        $music_format     = 'mp3,aac,wav,wma,cda,flac,m4a,mid,mka,mp2,mpa,mpc,ape,ofr,ogg,ra,wv,ac3,dts';

        $ext = $files->extension();

        $ext = strtolower($ext);

        if($flag == 'm'){

            $pic_video_format_arr = explode(',',$music_format);

        }elseif($flag == 'p'){

            $pic_video_format_arr = explode(',',$pic_format);

        }else{

            $pic_video_format_arr = explode(',',$pic_video_format);
        }

        if (!in_array($ext, $pic_video_format_arr)) {

            return ['code' => 1,'msg' => $msg,'data' => ''];die;
        }

    }
}
